package com.styletransfer.controller;

import com.styletransfer.model.ApiResponse;
import com.styletransfer.service.OssService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * 图片相关接口控制器
 */
@Slf4j
@RestController
@RequestMapping("/image")
@CrossOrigin
public class ImageController {

    @Autowired
    private OssService ossService;

    /**
     * 上传图片
     * @param file 图片文件
     * @param type 图片类型（可选，默认为image）
     * @return 上传结果
     */
    @PostMapping(value = "/upload", consumes = "multipart/form-data")
    public ApiResponse<Map<String, Object>> uploadImage(
            @RequestParam("file") MultipartFile file,
            @RequestParam(value = "type", required = false, defaultValue = "image") String type) {
        log.info("上传图片，类型：{}, 文件名: {}, 大小: {}", type, file.getOriginalFilename(), file.getSize());
        return ossService.uploadImage(file, type);
    }
}
